<template>
  <div>
    <van-cell title="搜索历史">
      <div v-if="deleteFlag">
        <span @click="$emit('clearAll')">全部删除</span>
        <span class="deleteSure" @click="deleteFlag = false">完成</span>
      </div>
      <van-icon v-else name="delete-o" @click="deleteFlag = true" />
    </van-cell>
    <van-empty v-if="!searchHistory.length" image="error" description="暂无历史记录" />
    <van-cell @click="linkSearch(item)" :title="item" v-for="(item, i) in searchHistory" :key="item">
      <van-icon @click.stop="removeHistory(i)"  v-if="deleteFlag" name="close" />
    </van-cell>
  </div>
</template>

<script>
// import { setItem, getItem } from '@/utils/storage'

export default {
  props: {
    searchHistory: {
      required: true,
      type: Array
    }
  },
  data () {
    return {
      deleteFlag: false
    }
  },

  created () {

  },

  methods: {
    removeHistory (i) {
      this.searchHistory.splice(i, 1)
    },
    linkSearch (value) {
      this.$emit('searchLink', value)
    }
  }
}
</script>

<style scoped lang='less'>
.deleteSure {
  margin-left: 10px;
}
</style>
